package com.ghost.alibabaghost.service.sys;

import com.ghost.alibabaghost.api.model.sys.GhostDeptModel;
import com.ghost.alibabaghost.api.service.sys.GhostDeptService;
import com.ghost.alibabaghost.dao.dataobject.sys.GhostDeptDO;
import com.ghost.alibabaghost.dao.mapper.sys.GhostDeptMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author yaolisheng
 * @version 1.0
 * @date 2022/1/24 05:20
 */
@Service("ghostDeptService")
public class GhostDeptServiceImpl implements GhostDeptService {

    @Autowired
    private GhostDeptMapper ghostDeptMapper;

    @Override
    public GhostDeptModel queryByDeptCode(String deptCode) {
       GhostDeptModel ghostDeptModel = new GhostDeptModel();
        BeanUtils.copyProperties( ghostDeptMapper.queryByDeptCode(deptCode),ghostDeptModel);
        return ghostDeptModel;
    }

    @Override
    public List<GhostDeptModel> queryAll() {
        return ghostDeptMapper.queryAll().stream().map(deptDO->{
            GhostDeptModel ghostDeptModel = new GhostDeptModel();
            BeanUtils.copyProperties(deptDO,ghostDeptModel);
            return ghostDeptModel;
        }).collect(Collectors.toList());
    }

    @Override
    public Integer insertDept(GhostDeptModel record) {
        GhostDeptDO ghostDeptDO = new GhostDeptDO();
        BeanUtils.copyProperties(record,ghostDeptDO);
        return ghostDeptMapper.insertDept(ghostDeptDO);
    }

    @Override
    public Integer updateDeptByCode(GhostDeptModel record) {
        GhostDeptDO ghostDeptDO = new GhostDeptDO();
        BeanUtils.copyProperties(record,ghostDeptDO);
        return ghostDeptMapper.updateDeptByCode(ghostDeptDO);
    }
}
